package com.zxx.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

@Component
public class QosListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {

        //处理业务
        System.out.println(new String(message.getBody()));

        //手动签收
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //不签收就不会消耗消息
        channel.basicAck(deliveryTag,true);
    }
}
